package com.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

public class ReaderConfig {
	
	private static Properties ps;
	
	private static String socketIpAddress;
	private static int socketPort;
	
	private static String ftpIpAddress;
	private static int ftpPort;
	private static String ftpUserName;
	private static String ftpPasswd;
	private static String cmValueReplace;
	private static String pmValueReplace;
	
	
	public static String getCmValueReplace() {
		return cmValueReplace;
	}

	public static String getPmValueReplace() {
		return pmValueReplace;
	}

	private static void ReaderConfigFile(String cfgFileName){
		try {
			InputStream in = new FileInputStream(new File(cfgFileName));
			ps = new Properties();
			ps.load(in);
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void initConfigVariable(){
		ReaderConfigFile(System.getProperty("user.dir")+"\\config\\config.properties");
		socketIpAddress = ps.getProperty("socket.ipAddress");
		socketPort = Integer.parseInt(ps.getProperty("socket.port"));
		
		ftpIpAddress = ps.getProperty("ftp.ipAddress");
		ftpPort = Integer.parseInt(ps.getProperty("ftp.port"));
		ftpUserName = ps.getProperty("ftp.userName");
		ftpPasswd = ps.getProperty("ftp.passWd");
		cmValueReplace = ps.getProperty("cm.replace");
		pmValueReplace = ps.getProperty("pm.replace");
	}
	
	public static String getSocketIpAddress() {
		return socketIpAddress;
	}

	public static int getSocketPort() {
		return socketPort;
	}

	public static String getFtpIpAddress() {
		return ftpIpAddress;
	}

	public static int getFtpPort() {
		return ftpPort;
	}

	public static String getFtpUserName() {
		return ftpUserName;
	}

	public static String getFtpPasswd() {
		return ftpPasswd;
	}
	
	public static void main(String[] args){
		ReaderConfig.initConfigVariable();
		System.out.println(ReaderConfig.getFtpIpAddress());
		System.out.println(System.getProperty("user.dir"));
	}
}
